﻿using KAsFrame.Application.Contracts.User;
using KAsFrame.Common.Const;
using KAsFrame.Common.Controllers;
using KAsFrame.Common.Dto;
using KAsFrame.Domain.User.Dto;
using KAsFrame.Domain.User.Entities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace KAsFrame.Application.Controller.User
{

    [Route(ConstConfig.ApiRouteConfig)]
    [ApiController]
    public class UserController : ControllerBase
    {

        private readonly IUserAppService _appService;

        public UserController(IUserAppService appService)
        {
            _appService = appService;
        }

        [HttpPost]
        [AllowAnonymous]
        public async Task<ApiResult<LoginReturnDto>> LoginAsync(LoginDto dto)
        {
            var result = ApiResult<LoginReturnDto>.IsSuccess();
            result.Data = await _appService.LoginAsync(dto);
            return result;
        }

        [HttpPost]
        [AllowAnonymous]
        public async Task<ApiResult<UserDto>> RegisterAsync(RegisterDto dto)
        {
            var result = ApiResult<UserDto>.IsSuccess();
            result.Data = await _appService.RegisterAsync(dto);
            return result;
        }
    }
}
